package com.armrest.screen.provider

import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.armrest.screen.HomeMenuModel
import com.armrest.screen.ItemViewType
import com.armrest.screen.R
import com.armrest.screen.setMediaPlayer
import com.chad.library.adapter.base.provider.BaseItemProvider
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class WindowModelProvider(
    private var layout: Int = R.layout.car_wind_home_layout, var itemViewTypes:
    Int = ItemViewType.ITEM_TYPE_GRAVITY_MODEL
) : BaseItemProvider<HomeMenuModel>() {
    override val itemViewType: Int
        get() = itemViewTypes
    override val layoutId: Int
        get() = layout
    var itemClick: ((position: Boolean) -> Unit)? = null
    var itemWindowClick: ((position: Boolean) -> Unit)? = null
    private var windowBoolean: Boolean = false
    private var gravityBoolean: Boolean = false
    override fun convert(helper: BaseViewHolder, item: HomeMenuModel) {
        val gravityLl = helper.getViewOrNull<LinearLayout>(R.id.window_ll)
        val gravityImg = helper.getViewOrNull<ImageView>(R.id.window_img)
        val tpisTv = helper.getViewOrNull<ImageView>(R.id.window_toast_tv)
        val openOff = helper.getViewOrNull<ImageView>(R.id.window_tv)
        gravityLl?.let {
            gravityLl.setOnClickListener {
                it.setMediaPlayer()
                it.setBackgroundResource(if (gravityBoolean) R.mipmap.car_window_off else R.mipmap.car_window_on)
                gravityImg?.setImageResource(if (gravityBoolean) R.mipmap.icon_car_window_off else R.mipmap.icon_car_window_open)
                tpisTv?.setImageResource(if (gravityBoolean) R.mipmap.text_car_window_wat_image else R.mipmap.text_car_window_bak_image)
                openOff?.setImageResource(if (gravityBoolean) R.mipmap.text_close_image else R.mipmap.text_start_on_image)
//                openOff?.text=(if (gravityBoolean) "已关闭" else "已打开")
                itemClick?.invoke(gravityBoolean)
                gravityBoolean = !gravityBoolean
            }
        }
        val windowOneLl = helper.getViewOrNull<LinearLayout>(R.id.window_one_ll)
        val windowOneImg = helper.getViewOrNull<ImageView>(R.id.window_one_img)
        val windowOneTv = helper.getViewOrNull<ImageView>(R.id.window_one_tv)
        val offOneTv = helper.getViewOrNull<ImageView>(R.id.off_one_tv)
        windowOneLl?.let {
            windowOneLl.setOnClickListener {
                it.setMediaPlayer()
                it.setBackgroundResource(if (windowBoolean) R.mipmap.icon_skylight_bg_on else R.mipmap.icon_skylight_bg_open)
                windowOneImg?.setImageResource(if (windowBoolean) R.mipmap.icon_skylight_off else R.mipmap.icon_skylight_on)
                windowOneTv?.setImageResource(if (windowBoolean) R.mipmap.text_window_wat_image else R.mipmap.text_window_bak_image)
                offOneTv?.setImageResource(if (windowBoolean) R.mipmap.text_close_image else R.mipmap.text_start_on_image)
//                offOneTv?.text=(if (windowBoolean) "已关闭" else "已打开")
                itemWindowClick?.invoke(windowBoolean)
                windowBoolean = !windowBoolean
            }
        }
    }
}